<script type ="text/javascript" src="../date/jquery.jdpicker.js"></script>
<link rel="stylesheet" href="../date/jdpicker.css" type="text/css" media="screen" /> 
<script type="text/javascript">
	cotCanHien[0] = 2;
	function guiform() 
	{  
		 document.formgui.submit(); 
	}
	
	function ChuyenMaKhachHang(MaKH){
		document.getElementById('MaKH').value = MaKH;
	}

	function GetThongTinKhachHang(MaKH){
		var xmlHttp;
	    if(window.XMLHttpRequest){
	        xmlHttp = new XMLHttpRequest;
	    }
	    else if(window.ActiveXObject){
	        xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');
	    }
	    
	    xmlHttp.onreadystatechange = function(){
	        if(xmlHttp.readyState == 4){
	            var thongTin = xmlHttp.responseText;
	            var mangThongTin = thongTin.split("|");
	            document.getElementById('NgaySinh').value = mangThongTin[0];
	            document.getElementById('DiaChi').value = mangThongTin[1];
	            document.getElementById('SoCMND').value = mangThongTin[2];
	            document.getElementById('NgayCap').value = mangThongTin[3];
	            document.getElementById('NoiCap').value = mangThongTin[4];
	        }
	    }
	    xmlHttp.open('GET', '../adm/nhanvien/taisanthechap/getthongtinkhachhang.php?makh='+MaKH, true);
	    xmlHttp.send(null);
	}
	
	function tinhGiaTriDat(){
	 	var xmlHttp;
	 	var DienTichDat = document.getElementById('DienTichDat').value;
	    if(window.XMLHttpRequest){
	        xmlHttp = new XMLHttpRequest;
	    }
	    else if(window.ActiveXObject){
	        xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');
	    }
	    
	    xmlHttp.onreadystatechange = function(){
	        if(xmlHttp.readyState == 4){
	        	document.getElementById('GiaTriTaiSan').value = Math.round(parseFloat(DienTichDat) * 50000000 / 1000);
	        }
	    }
	    xmlHttp.open('GET', '', true);
	    xmlHttp.send(null);
	}

	function ajaxFunction(id){
	    var xmlHttp;
	    if(window.XMLHttpRequest){
	        xmlHttp = new XMLHttpRequest;
	    }
	    else if(window.ActiveXObject){
	        xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');
	    }
	    
	    xmlHttp.onreadystatechange = function(){
	        if(xmlHttp.readyState == 4){
	            document.getElementById('MaHinhThucVay').innerHTML = xmlHttp.responseText;
	        }
	    }
	    xmlHttp.open('GET', '../adm/nhanvien/hopdongtindung/comboboxkyhantra.php?dmid='+id, true);
	    xmlHttp.send(null);
	}
</script>


<?php
	$taisanthechap = new taisanthechapbs();
	$danhsach = $taisanthechap->LayDanhSach();
	session_start();
	$nhatky = new nhatkybs();
	$nhatky->TenSuKien = "Xem danh sách hợp đồng thế chấp";
	$nhatky->MaNguoiDung = $_SESSION["MaND"];
	date_default_timezone_set('Asia/Ho_Chi_Minh');
	$nhatky->ThoiGian = date("Y-m-d H:m:s", time());
	$nhatky->Them();
?>
<form name="formgui"  method="POST" action="">
<table id="rounded-corner" class="display" summary="Danh sách hợp đồng thế chấp" border="1">
	<thead>
		<tr>
			<th align="center" colspan="13">
	               	<h2><strong>DANH SÁCH HỢP ĐỒNG THẾ CHẤP</strong></h2>
			</th>
		</tr>
		<tr>					
			<th scope="col" class="rounded">STT</th>
			<th scope="col" class="rounded">Số HĐTC</th>
			<th scope="col" class="rounded">Tài khoản</th>
			<th scope="col" class="rounded">Số QSDĐ</th>			
			<th scope="col" class="rounded">Nơi cấp đất</th>
			<th scope="col" class="rounded">Tổng diện tích</th>
			<th scope="col" class="rounded">Giá trị tài sản</th>		
		</tr>
	</thead>
	<tfoot>
            <tr>
            	<th>STT</th>
            	<th>Số HĐTC</th>
                <th>Tài khoản</th>
                <th>Số QSDĐ</th>
                <th>Nơi cấp đất</th>          
                <th>Tổng diện tích</th>
                <th>Giá trị tài sản</th>                            
            </tr>
    </tfoot>
	<tbody>
		<?php
		$stt = 1;
		for($i = 0; $i < ($danhsach == false ? 0 : count($danhsach)); $i++)
		{
				echo "<tr>";
					echo "<td>" . ($i + 1) . "</td>";
					echo "<td><a onclick='toggleSua();' href='index.php?do=taisanthechap&id={$danhsach[$i]["SoHDTC"]}'>{$danhsach[$i]['SoHDTC']}</a></td>";
					echo "<td>{$danhsach[$i]['MaKH']}</td>";
					echo "<td>{$danhsach[$i]['SoQSDD']}</td>";
					echo "<td>{$danhsach[$i]['NoiCapDat']}</td>";
					echo "<td>{$danhsach[$i]['TongDienTich']}</td>";
					echo "<td>{$danhsach[$i]['GiaTriTaiSan']}</td>";									
					
				echo "</tr>";
					$stt++;
		}
			?>
	</tbody>
</table>
</form>
<br/><br/>
<?php
	$taisanthechap = new taisanthechapbs();
	$taisanthechap->SoHDTC = $_GET["id"];
	$danhsach = $taisanthechap->LayDanhSach();
?>
<br/>
<div class="form" id="tdSua" style="<?php if($_GET['id']!="") echo "display:block"; else echo "display:none"; ?>">
<form enctype="multipart/form-data" name="formgui"  method="post" action="index.php?do=suataisanthechap_xuly" onsubmit="return checkPostArtForm(this);">
<h2>
	<strong>Thông tin hợp đồng thế chấp</strong>
</h2><table style="width:950px; margin-left: 10px; table-layout: fixed;">
		<tr>
			<td style="width:20px;padding-top:10px;">
	        	<label for="mataisanthechap">Số HĐTC:</label>        	
	        </td>
	        <td style="width:60px;padding-top:10px;">
	            <input readonly="readonly" tabindex="1" type="text" id="SoHDTC" name="SoHDTC" class="txt" size="12" value="<?php echo $danhsach[0]["SoHDTC"];?>"/>  
	        </td>
	        <td style="width:20px;padding-top:10px;">

	        </td>
	        <td style="width:60px;padding-top:10px;">

	        </td>
		</tr>
		<tr>
			<td style="padding-top:10px;">
	        	<label for="tenkhachhang">Khách hàng:</label>   	
	        </td>	       
			<td style="padding-top:10px;">
				<select disabled="disabled" name="TenKhachHang" onchange="ChuyenMaKhachHang(this.value);GetThongTinKhachHang(this.value);">		
            		<option value="0">-- Chọn khách hàng --</option>	                      	
					<?php
						$khachhang = new khachhangbs();
						$danhsachkhachhang = $khachhang->LayDanhSach();
						for($j = 0; $j < ($danhsachkhachhang != false ? count($danhsachkhachhang) : 0); $j++)
						{	
							$HoTen = $danhsachkhachhang[$j]['Ho'] . " "	. $danhsachkhachhang[$j]['Ten'];
							if($danhsachkhachhang[$j]["MaKH"]==$danhsach[0]["MaKH"])	
								echo "<option selected value='{$danhsachkhachhang[$j]["MaKH"]}'>{$HoTen}</option>";
							else 
								echo "<option value='{$danhsachkhachhang[$j]["MaKH"]}'>{$HoTen}</option>";
						}
					?>
				</select>
			</td>
		</tr>
		<tr>
			<td style="padding-top:10px;">
	        	<label for="makhachhang">Tài khoản:</label>      	
	        </td>
			 <td style="padding-top:10px;">
	        	<input readonly="readonly" tabindex="1" type="text" id="MaKH" name="MaKH" class="txt" size="12" value="<?php echo $danhsach[0]["MaKH"];?>" /> 
	        </td>
	        <?php 
			$kh = new khachhangbs();
			$kh->MaKH = $danhsach[0]["MaKH"];
			$dskhachhang = $kh->LayDanhSach();
			?>
	        <td style="padding-top:10px;">
	        	<label for="ngaysinh">Ngày sinh:</label>            	
	        </td>	       
			<td style="padding-top:10px;">
	        	<input readonly="readonly" tabindex="1" type="text" id="NgaySinh" name="NgaySinh" class="txt" size="12" value="<?php echo $dskhachhang[0]["NgaySinh"];?>" /> 
	        </td>
		</tr>
		<tr>
			<td style="padding-top:10px;">
	        	<label for="diachi">Địa chỉ:</label>         	
	        </td>	       
			<td style="padding-top:10px;">
	        	<input readonly="readonly" tabindex="1" type="text" id="DiaChi" name="DiaChi" class="txt" size="12" value="<?php echo $dskhachhang[0]["DiaChi"];?>" /> 
	        </td>
			<td style="padding-top:10px;">
	        	<label for="socmnd">Số CMND:</label>        	
	        </td>
			 <td style="padding-top:10px;">
	        	<input readonly="readonly" tabindex="1" type="text" id="SoCMND" name="SoCMND" class="txt" size="12" value="<?php echo $dskhachhang[0]["SoCMND"];?>" /> 
	        </td>
		</tr>
		<tr>
			<td style="padding-top:10px;">
	        	<label for="ngaycap">Ngày cấp:</label>          	
	        </td>	       
			<td style="padding-top:10px;">
	        	<input readonly="readonly" tabindex="1" type="text" id="NgayCap" name="NgayCap" class="txt" size="12" value="<?php echo $dskhachhang[0]["NgayCap"];?>" /> 
	        </td>
			<td style="padding-top:10px;">
	        	<label for="noicap">Nơi cấp:</label>        	
	        </td>
			 <td style="padding-top:10px;">
	        	<input readonly="readonly" tabindex="1" type="text" id="NoiCap" name="NoiCap" class="txt" size="12" value="<?php echo $dskhachhang[0]["NoiCap"];?>" /> 
	        </td>
		</tr>
		<tr>
			<td align="center" colspan="0">
			<hr>
			</td>
		</tr>		
		<tr>
			<td style="padding-top:10px;">
	        	<label for="nguoithuake">Người thừa kế:</label>&nbsp<span class="requirefield">*</span>         	
	        </td>	       
			<td style="padding-top:10px;">
	        	<input tabindex="1" type="text" name="NguoiThuaKe" class="txt" value="<?php echo $danhsach[0]["NguoiThuaKe"];?>" required oninvalid="this.setCustomValidity('Bạn chưa nhập người thừa kế')" onchange="this.setCustomValidity('');"/>
	        </td>
	        <td style="padding-top:10px;">
	        	<label for="ngaysinh1">Ngày sinh:</label>&nbsp<span class="requirefield">*</span>         	
	        </td>	       
			<td style="padding-top:10px;">
				<input tabindex="1" type="text" name="NgaySinh1" class="jdpicker" value="<?php echo $danhsach[0]["NgaySinh"];?>" />  
	        </td>
	    </tr>
	    <tr>
			<td style="padding-top:10px;">
	        	<label for="diachi1">Địa chỉ:</label>&nbsp<span class="requirefield">*</span>              	
	        </td>	       
			<td style="padding-top:10px;">
	        	<input tabindex="1" type="text" name="DiaChi1" class="txt" value="<?php echo $danhsach[0]["DiaChi"];?>" required oninvalid="this.setCustomValidity('Bạn chưa nhập địa chỉ')" onchange="this.setCustomValidity('');"/> 
	        </td>
			<td style="padding-top:10px;">
	        	<label for="socmnd1">Số CMND:</label>&nbsp<span class="requirefield">*</span>           	
	        </td>
			 <td style="padding-top:10px;">
	        	<input tabindex="1" type="text" name="SoCMND1" class="txt" value="<?php echo $danhsach[0]["SoCMND"];?>" required oninvalid="this.setCustomValidity('Bạn chưa nhập số CMND')" onchange="this.setCustomValidity('');"/>
	        </td>
		</tr>
		<tr>
			<td style="padding-top:10px;">
	        	<label for="ngaycap1">Ngày cấp:</label>&nbsp<span class="requirefield">*</span>             	
	        </td>	       
			<td style="padding-top:10px;">
	        	<input tabindex="1" type="text" name="NgayCap1" class="jdpicker" value="<?php echo $danhsach[0]["NgayCap"];?>" />  
	        </td>
			<td style="padding-top:10px;">
	        	<label for="noicap1">Nơi cấp:</label>&nbsp<span class="requirefield">*</span>           	
	        </td>
			 <td style="padding-top:10px;">
	        	<input tabindex="1" type="text" name="NoiCap1" class="txt" value="<?php echo $danhsach[0]["NoiCap"];?>" required oninvalid="this.setCustomValidity('Bạn chưa nhập nơi cấp')" onchange="this.setCustomValidity('');"/>  
	        </td>
		</tr>		
		<tr>
			<td colspan="0">
			<hr>
			</td>
		</tr>
		<tr>
			<td style="padding-top:10px;">
	        	<label for="soqsdd">Số QSDĐ:</label>       	
	        </td>	       
			<td style="padding-top:10px;">
	        	<input readonly="readonly" tabindex="1" type="text" id="SoQSDD" name="SoQSDD" class="txt" size="12" value="<?php echo $danhsach[0]["SoQSDD"];?>" />
	        </td>
	    </tr>		
		<tr>
			<td style="padding-top:10px;">
	        	<label for="noicapdat">Nơi cấp đất:</label>         	
	        </td>	       
			<td style="padding-top:10px;">
	        	<input readonly="readonly" tabindex="1" type="text" id="NoiCapDat" name="NoiCapDat" class="txt" size="12" value="<?php echo $danhsach[0]["NoiCapDat"];?>" />
	        </td>
	        <td style="padding-top:10px;">
	        	<label for="ngaycapdat">Ngày cấp đất:</label>        	
	        </td>	       
			<td style="padding-top:10px;">
	        	<input readonly="readonly" tabindex="1" type="text" id="NgayCapDat" name="NgayCapDat" class="txt" size="12" value="<?php echo $danhsach[0]["NgayCapDat"];?>" />
	        </td>
		</tr>	
		<tr>
			<td style="padding-top:10px;">
	        	<label for="thuadatso">Thửa đất số:</label>     	
	        </td>	       
			<td style="padding-top:10px;">
	        	<input readonly="readonly" tabindex="1" type="text" id="ThuaDatSo" name="ThuaDatSo" class="txt" size="12" value="<?php echo $danhsach[0]["ThuaDatSo"];?>" />
	        </td>
	        <td style="padding-top:10px;">
	        	<label for="diachithuadat">Địa chỉ thửa đất:</label>      	
	        </td>	       
			<td style="padding-top:10px;">                     	
						<?php
							$diaban = new diabanbs();
							$diaban->MaDiaBan =  $danhsach[0]['MaDiaBan'];
							$danhsachdiaban = $diaban->LayDanhSach();
							?>
				<input readonly="readonly" tabindex="1" type="text" id="MaDiaBan" name="MaDiaBan" class="txt" size="12" value="<?php echo $danhsachdiaban[0]["TenDiaBan"];?>" />			
	        </td>
		</tr>	
		<tr>
			<td style="padding-top:10px;">
	        	<label for="tobandoso">Tờ bản đồ số:</label>      	
	        </td>	       
			<td style="padding-top:10px;">
	        	<input readonly="readonly" tabindex="1" type="text" id="ToBanDoSo" name="ToBanDoSo" class="txt" size="12" value="<?php echo $danhsach[0]["ToBanDoSo"];?>" />
	        </td>
	        <td style="padding-top:10px;">
	        	<label for="tongdientich">Tổng diện tích:</label>        	
	        </td>	       
			<td style="padding-top:10px;">
	        	<input readonly="readonly" tabindex="1" type="text" id="TongDienTich" name="TongDienTich" class="txt" size="12" value="<?php echo $danhsach[0]["TongDienTich"];?>" />
	        </td>
		</tr>	
		<tr>
			<td style="padding-top:10px;">
	        	<label for="giatritaisan">Giá trị tài sản:</label>       	
	        </td>	       
			<td style="padding-top:10px;">
	        	<input readonly="readonly" tabindex="1" type="text" id="GiaTriTaiSan" name="GiaTriTaiSan" class="txt" size="12" value="<?php echo $danhsach[0]["GiaTriTaiSan"];?>" />
	        </td>
			<td style="padding-top:10px;">
	        	<label for="mucchovay">Mức cho vay:</label>       	
	        </td>	       
			<td style="padding-top:10px;">
	        	<input id="MucChoVay" readonly="readonly" tabindex="1" type="text" name="MucChoVay" class="txt" size="12" value="<?php echo $danhsach[0]["MucChoVay"];?>" />
	        </td>
	      </tr>
		<p class="requirefields">(*): Các trường bắt buộc phải có.</p>
</table>
<br/>
<br/>
<p align="center">
	<input type="submit" class="button small blue" value="Cập nhật"/>
	&nbsp &nbsp
	<a href="index.php?do=laphopdongtindung&id=<?php echo $_GET["id"];?>" class="button small blue">Lập hợp đồng tín dụng</a>	
</p>
</form>
</div>
<br/>
<br/>
<?php
	if(isset($_SESSION["LoiSuaTaiSanTheChap"]))
	{
		echo $_SESSION["LoiSuaTaiSanTheChap"];
		unset($_SESSION["LoiSuaTaiSanTheChap"]);
	}
?>

<script type="text/javascript">
function checkPostArtForm(frm)
{
    var re =  /[0-9]{9}/;
	if(!frm.SoCMND1.value.match(re) || frm.SoCMND1.value.length != 9)
	{
		alert('CMND phải gồm 9 số.');
		frm.SoCMND1.focus();
		return false;
	}
}
</script>


